'use strict';

app.factory('apiService', ['$q', '$rootScope', '$http', '$cookieStore', function ($q, $rootScope, $http, $cookieStore) {
    // var url = 'http://192.168.0.186:8080/MemberManage/'; //珊珊
    // var url = 'http://192.168.0.178:8080/MemberManage/';//明明
    // var url = 'http://47.104.227.246:8080/MemberManage/';
    var url = 'http://192.168.0.178:8080/MemberManage/';//闯
    // var url = 'http://192.168.0.171:1530/MemberManage/';
    $rootScope.userObj = $cookieStore.get('cy__admin');
    var apiObj = {
        post: function (urlParms, postData, successCall, errCall) {
            var postDefault = {
                'md5Name': $rootScope.userObj ? $rootScope.userObj['md5Name'] : '',
                'md5Id': $rootScope.userObj ? $rootScope.userObj['id'] : ''
            };

            postData['md5Name'] = postDefault['md5Name'];
            postData['md5Id'] = postDefault['md5Id'];

            $http({
                method: 'POST',
                url: url + urlParms['modelName'] + '/' + urlParms['apiName'],
                data: postData
            }).success(function (data, status, headers, config) {
                successCall(data);
            }).error(function (data, status, headers, config) {
                if (errCall) {
                    errCall(data);
                }else{
                    console.log(data);
                }
            });
        }
    };

    return apiObj;
}]);